<?php
/**
 * ClassName: PerformanceLogService
 * Description:
 * @Author 周昌
 * @Create 2024/1/18 10:13
 */

namespace service\admin;


use model\AdminModel;
use service\BaseService;
use think\Db;

class PerformanceLogService extends BaseService
{
    protected static $model='model\PerformanceLogModel';

    //绩效详情列表数据
    public static function getInfoData($where)
    {
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],''):'';
            return $data;
        });
    }

    //统计列表数据
    public static function getAjaxData($where)
    {
//        $table = self::$model::order('id desc');
        $table=AdminModel::alias('a')->leftJoin('performance_log p','a.id=p.admin_id')
            ->where($where)->field("a.id,a.hospital_id,a.group_name,count(p.id) as count,sum(p.money) as sum")
            ->group('a.id')->order('sum desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['sum']=$data['sum']??0;
            $data['hospital_name'] = $data['hospital_id']?HospitalService::getNameByKey($data['hospital_id'],'','id,name','id','hospital_key_name'):'';
            return $data;
        });
    }

}